<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>登录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="login.css">
</head>

<body>
	<div class="layui-form" action="" method="post">
		<div class="container">
			<img src="../../images/logo.png" style="width:200px; margin-left: 90px;" />
			<div class=" layui-word-aux">
				盘珠珠后台管理系统
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">登录帐号</label>
				<div class="layui-input-block">
					<input id="username" type="text" name="username" required lay-verify="username" placeholder="登录帐号"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">密 &nbsp;&nbsp;码</label>
				<div class="layui-input-block">
					<input id="pass" type="password" name="userpassword" required lay-verify="pass" placeholder="密码"
						autocomplete="off" class="layui-input">
				</div>
				<!-- <div class="layui-form-mid layui-word-aux">辅助文字</div> -->
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">验证码</label>
				<div class="layui-input-block" style="width: auto;">
					<input type="text" id="verifycode" name="verifycode" required lay-verify="verifycode"
						placeholder="验证码" autocomplete="off" class="layui-input verity">
					<a href="javascript:;" id="yzm" style="position: absolute; margin-left: 10px ;"></a>
				</div>

			</div>

			<button id="btn_submit" class="layui-btn" lay-filter="formDemo">登&nbsp;&nbsp;录</button>
		</div>
	</div>
	<div class="loginBg"></div>
	<canvas id="bgCanvas"></canvas>

	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script src="ribbon.js" type="text/javascript" charset="utf-8"></script>
	<script>
		layui.use(['form', 'layer'], function () {
			var form = layui.form,
				$ = layui.jquery;

			form.verify({
				username: function (value, item) { //value：表单的值、item：表单的DOM对象
					if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
						return '帐号不能有特殊字符';
					}
					if (/(^\_)|(\__)|(\_+$)/.test(value)) {
						return '帐号首尾不能出现下划线\'_\'';
					}
					if (/^\d+\d+\d$/.test(value)) {
						return '帐号不能全为数字';
					}
				},
				pass: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'],
				verifycode: [/^[\S]{4}$/, '请填写4位验证码']
			});
			//监听提交
			$('#btn_submit').click(function () {
				(async function () {
					var index = layer.msg('登录中，请稍候', {
						icon: 16,
						time: false,
						shade: 0.8
					});

					let data = await ajaxAsync('login', {
						uname: $('#username').val(),
						pwd: $('#pass').val(),
						verifycode: $('#verifycode').val()
					}, 'POST', (err) => {
						initVerifCode();
						layer.close(index);
					});

					layui.data('currLoginInfo', {
						key: 'data',
						value: data
					});
					window.location.href = "../../index.html";
				})();
				return false; //避免submit之后重置表单
			});

			async function initVerifCode() {
				let data = await ajaxAsyncNoTip("login", {
					t: Math.random()
				})
				$("#yzm").empty().html(data)
			}
			initVerifCode();
			$('#yzm').click(initVerifCode);
		});
	</script>
</body>

</html>